/**
 *	Copyright (c) 1996-2010 Maxim Shklyar, kisla interactive, kisla.com 
 *	All rights reserved.
**/

package com.kisla.Xslidenav
{
	import flash.net.URLRequest;
	import flash.display.Loader;

	import fl.transitions.Tween;
	import fl.transitions.TweenEvent;
	import fl.transitions.easing.*;


	import flash.display.MovieClip;


	public class Xslides extends MovieClip {

		private var conf_xml:XML;
		private var data_xml:XML;

		private var tw:Tween;


		public function Xslides(cx:XML, dx:XML)
		{
			conf_xml = cx;
			data_xml = dx;
		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		public function init() {

			var i:int = 0;
			for each(var sx:XML in data_xml.slides.s) {
				//trace("slide: " + sx.toXMLString());

				if (sx.@src.length()>0)
				{
					var img_ldr = new Loader();
					img_ldr.load(new URLRequest(sx.@src));
					this.addChild( img_ldr );

					img_ldr.x = conf_xml.layout.@xd * i++;
				}
			}

		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		public function upd_slds_pos(curr_sl:int):void
		{

			if (conf_xml.speed.@change>0) {
				tw = new Tween(this, "x", Regular.easeOut, this.x, -conf_xml.layout.@xd*curr_sl, conf_xml.speed.@change, true);
				tw.addEventListener(TweenEvent.MOTION_FINISH, function(){  this.x = -conf_xml.layout.@xd*curr_sl; } );
			}
			else
				this.x = -conf_xml.layout.@xd*curr_sl;

		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

	}
}
